%{
    This file is part of StemCellQC, a video bioinformatics software
    toolkit for analysis of phase contrast microscopy videos.
    Copyright 2013-2015 Vincent On. [vincenton001-at-gmail.com]

    StemCellQC is free software: you can redistribute it and/or 
    modify it under the terms of the GNU General Public License as 
    published by the Free Software Foundation, either version 3 of the 
    License, or (at your option) any later version.

    StemCellQC is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with StemCellQC.  If not, see <http://www.gnu.org/licenses/>.
%}

function [N_protrusions, Prot_area] = protrusions(index, seg, area_thres) 

%open segmented region with large disk
se = strel('disk',30); 
sil = imopen(seg,se);

%remove over lapping region
protru_sil = seg;
protru_sil(sil ~= 0) = 0;

%remove regions that have fewer pixels than threshold
protru_sil = bwareaopen( protru_sil, area_thres );

%find connected regions
protru_sil = bwlabel(protru_sil);

% mov(index).protrusions = protru_sil;
N_protrusions = max( max( protru_sil ));
Prot_area = nnz( protru_sil );
